<template>
	<view class="home" :style="bgStyle">
		<custom-navbar title="公司主页" :show-back="true" @back="handleBack" />

		<view class="content p2030" :style="{ paddingTop: navBarHeight + 'px' }">
			<view class="mb48">
				<view class="information p40 mt20">
					<view class="enterprise mb30  fcsb">
						<view class="fc">
							<image class="wh70" :src="companyData.institution_logo || '/static/images/default-logo.png'"
								mode="aspectFill"></image>
							<view class="ml25">
								<view class="f326c0 mb10">{{companyData.enterprise_name}}</view>
								<view class="f245c3">{{companyData.enterprise_size}}人 ·
									{{companyData.enterprise_address}}
								</view>
							</view>
						</view>
						<!-- 	<image class="wh26" src="/static/images/talents/更多.svg"></image> -->
					</view>
					<up-line></up-line>
					<view class="mt30">
						<view class="f30bc3 mb7">基本信息</view>
						<view class="f245c5">
							<view>所在地：{{companyData.province_id_text}}·{{companyData.district_id_text}}</view>
							<view>公司地址：{{companyData.enterprise_address}}</view>
							<view>联系人：{{companyData.contact_person}}</view>
							<view>联系电话：{{companyData.contact_number}}</view>
						</view>
					</view>
				</view>
				<view class="information p30 mt20">
					<view class="mb30">
						<view class="f30bc3 mb7">公司简介</view>
						<view class="f245c5">

							<mp-html :content="companyData.company_introduction" />
						</view>
					</view>
					<up-line></up-line>
					<view class="mb20 mt20">
						<view class="f30bc3 mb20">企业资质</view>
						<view class="f245c5" v-if="companyData.enterprise_qualification">
							<mp-html :content="companyData.enterprise_qualification" />
						</view>
						<view class="f245c5" v-else>暂无资质信息</view>
					</view>
				</view>
			</view>
			<view class="lsit" v-if="companyData.recruitment">
				<view class="tilte mb37">
					<view class="f36bc0">在招职位</view>
					<image class="tliteimg" src="/static/images/home/波浪.svg"></image>
				</view>
				<view class="supplyList">
					<view class="item p30 mb20" @click="handledetails(companyData.recruitment.recruitment_id)">
						<view class="fcsb mb18">
							<view class="f36bc0">{{companyData.recruitment.position_name}}</view>
							<view class="f36bcFF0C10">{{companyData.recruitment.salary_range_text}}</view>
						</view>
						<view class="f225c0 mb18">
							{{companyData.recruitment.enterprise_id_text}}·{{companyData.recruitment.enterprise_size_text}}人
						</view>
						<view class="fc mb30">
							<view class="condition mr10 p0020">
								<view>{{companyData.recruitment.province_id_text}}</view>
							</view>
							<view class="condition mr10 p0020">
								<view>{{companyData.recruitment.work_experience_text}}</view>
							</view>
							<view class="condition mr10 p0020">
								<view>{{companyData.recruitment.education_requirement_text}}</view>
							</view>
						</view>
						<up-line></up-line>
						<view class="f22c9 mt30">{{companyData.recruitment.create_time}}发布</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import CustomNavbar from '@/components/custom-navbar.vue'
	import supplyModal from '@/components/supplyModal.vue';
	import {
		ref,
		onMounted,
		computed
	} from 'vue';
	import {
		company
	} from '@/api/talents'
	import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
	// 2. 获取系统信息（同步操作放在setup最前面）
	const systemInfo = uni.getSystemInfoSync()

	// 3. 定义响应式数据
	const searchKey = ref('')
	const companyData = ref({}) // 存储公司数据

	// 4. 计算属性
	const navBarHeight = computed(() => systemInfo.statusBarHeight + 44)
	// 供需大厅
	const bgStyle = ref({})
	const enterprise_id = ref(null)
	// 初始化
	onMounted(() => {
		bgStyle.value = {
			backgroundImage: `url(https://gx.jifgou.com/image/homebg.png)`,
			backgroundSize: '100% auto',
			backgroundRepeat: 'no-repeat',
			minHeight: '100vh'
		}


		setTimeout(() => {
			const pages = getCurrentPages()
			const currentPage = pages[pages.length - 1]
			const options = currentPage.options
			enterprise_id.value = options.enterprise_id
			getCompanyInfo()
		}, 100)
	})

	// 获取公司信息
	const getCompanyInfo = async () => {
		try {
			const res = await company({
				enterprise_id: enterprise_id.value
			})
			if (res.code === 200) {
				companyData.value = res.data.data
				// 处理地址文本
				if (companyData.value.recruitment) {
					companyData.value.province_id_text = companyData.value.recruitment.province_id_text
					companyData.value.district_id_text = companyData.value.recruitment.district_id_text
				}
			}
		} catch (error) {
			console.error('获取公司信息失败:', error)
		}
	}

	const showModal = ref(false);
	const handleBack = () => {
		uni.switchTab({
			url: '/pages/index/index'
		});
	};
	const handledetails = (id) => {
		console.log(id)
		uni.navigateTo({
			url: `/pages/talents/position?recruitment_id=${id}`
		});
	};
	const handleResume = () => {
		uni.navigateTo({
			url: `/pages/resume/index`
		});
	}
</script>

<style lang="scss" scoped>
	.home {
		width: 100%;
		min-height: 100vh;
		position: relative;

		.content {
			padding-top: var(--status-bar-height);
			padding-top: calc(var(--status-bar-height) + 70rpx);
			/* 导航栏高度 */
			display: flex;
			flex-direction: column;

			.information {
				width: 100%;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;

				.wh70 {
					width: 70rpx;
					height: 70rpx;
					border-radius: 50%;
					overflow: hidden;
				}
			}

			.lsit {
				width: 100%;

				.tilte {
					position: relative;

					.tliteimg {
						width: 75rpx;
						height: 15.37rpx;
						position: absolute;
						bottom: -8rpx;
						left: 30rpx;
					}
				}

				.supplyList {
					.item {
						width: 100%;
						background: #FFFFFF;
						border-radius: 20rpx 20rpx 20rpx 20rpx;
						border: 1rpx solid;
						border-image: linear-gradient(61deg, rgba(57, 141, 251, 0), rgba(255, 255, 255, 1)) 1 1;

						.condition {
							height: 44rpx;
							background: rgba(146, 146, 146, 0.1);
							border-radius: 8rpx 8rpx 8rpx 8rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 20rpx;
							color: #A1A1A1;
							line-height: 44rpx;
							text-align: center;
							font-style: normal;
							text-transform: none;
						}
					}
				}
			}

		}
	}
</style>